package com.tcheung.web.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * PdfToSwf
 *
 * @author: zhangteng
 * @time: 2014/12/14 15:21
 */
public class PdfToSwf {

    private static void run() throws IOException {
        String pdfDir = "E:\\TCheungIR\\pdf";
        String swfDir = "E:\\TCheungIR\\swf";
        String swfToolsDir = "D:\\soft\\SWFTools";

        File file = new File(pdfDir);
        if (!file.isDirectory()) {
            return ;
        }
        File[] pdfFiles = file.listFiles();
        int pdfFileNumber = pdfFiles.length;
        for (int i = 0;i < pdfFileNumber; ++i) {
            File pdfFile = pdfFiles[i];
            StringBuilder commond = new StringBuilder();
            String swfFileName = pdfFile.getName().substring(0, pdfFile.getName().indexOf(".pdf")) + ".swf";

            swfFileName = swfDir + "//" + swfFileName;

            commond.append(swfToolsDir).append("//pdf2swf.exe ").append(pdfFile.getAbsolutePath()).append(" -o").append(swfFileName).append(" -T 9");
            Process process = Runtime.getRuntime().exec(commond.toString());
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str = null;
            while ((str = br.readLine()) != null) {
                System.out.println(str);
            }
        }
    }

    public static void main(String[] args) {
        System.out.println("gg");
        try {
            PdfToSwf.run();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
